<template>
	<view class="my-content">
		<view class="u-flex tableHead u-text-center padding-sm">
			<view class="u-flex-1">{{$t("模板名称")}}</view>
			<view class="u-flex-1">{{$t("邮件主题")}}</view>
			<view class="u-flex-1">{{$t("操作")}}</view>
		</view>
		<u-swipe-action :show="item.show" class="u-margin-bottom-20" v-for="(item,index) in listData" :key="index"
			:index="index" @click="click" @open="open" :options="options">
			<view class="u-flex u-text-center bgWhite padding-sm ">
				<view class="u-flex-1 u-line-1">立卡圣诞节福利卡仕达</view>
				<view class="u-flex-1 u-line-1">大方阿斯蒂芬阿斯蒂芬</view>
				<view class="u-flex-1 u-line-1" @click="editor(item)">
					<u-icon name="edit-pen" size="35"></u-icon>
				</view>
			</view>
		</u-swipe-action>
		<view class="footer">
			<u-button type="primary" :custom-style="customStyle" hover-class="none" @click="toCreateTemplate">
				{{$t("新建模板")}}
			</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customStyle: {
					background: 'linear-gradient(110deg, #DD2910 0%, #F79B29 100%)',
					'border-radius': '15rpx',
					'width': '480rpx',
				},
				listData: [{
					name: "模板名称",
					title: "主题"
				}, {
					name: "模板名称222",
					title: "主题333"
				}],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}]
			};
		},
		methods: {
			click(index) {
				console.log(index);
			},
			editor(row) {
				console.log(row);
			},
			toCreateTemplate() {
				this.$u.route({
					url: 'pages/getCustomer/createTemplate/createTemplate'
				})
			},
			open(index) {
				console.log(index);
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.listData[index].show = true;
				this.listData.map((val, idx) => {
					if (index != idx) {
						this.$set(this.listData[idx], 'show', false)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my-content {
		background-color: #f6f6f6;
		height: auto;
		min-height: 100%;
		padding-bottom: 110rpx;

		.bgWhite {
			background: #fff;
		}

		.padding-sm {
			padding: 20rpx 24rpx;
		}

		.footer {
			position: fixed;
			left: 0;
			bottom: 20rpx;
			width: 100%;
			text-align: center;
		}
	}
</style>